//
//  XPlanRecordTableViewCell.m
//  iPlan
//
//  Created by 侯伟 on 2021/9/9.
//

#import "XPlanRecordTableViewCell.h"
#import "XPlanModel.h"

@interface XPlanRecordTableViewCell (){
    
    UILabel* _titleLb;
    UILabel* _countLb;//数量
    UILabel* _stateLb;//状态
}
/// 显示内容视图
@property(nonatomic,weak) MyRelativeLayout* contentLayout;

@end

@implementation XPlanRecordTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self initSubViews];
    }
    return self;
}

- (void)initSubViews{
    
    MyRelativeLayout *contentLayout = [MyRelativeLayout new];
    contentLayout.padding = UIEdgeInsetsMake(16, 16,16, 16);
    contentLayout.myMargin = 0;
    contentLayout.myHeight = MyLayoutSize.wrap;
    contentLayout.cacheEstimatedRect = YES;
    [self.contentView addSubview:contentLayout];
    _contentLayout = contentLayout;
    
    UILabel* titleLb = [UILabel lableWithFont:FONT_FIT(18) color:COLOR_BLACK_DARK text:@"--"];
    titleLb.myLeft = titleLb.myTop = 0;
    [contentLayout addSubview:titleLb];
    _titleLb = titleLb;

    UILabel* countLb = [UILabel lableWithFont:FONT_FIT(15) color:COLOR_GRAY_QUITE text:@"0 / 0"];
    countLb.myLeft = 0;
    countLb.topPos.equalTo(titleLb.bottomPos).offset(16);
    [contentLayout addSubview:countLb];
    _countLb = countLb;
    
    UILabel* statueLb = [UILabel lableWithFont:FONT_FIT(10) color:COLOR_RED text:@"已完成"];
    statueLb.textAlignment = NSTextAlignmentCenter;
    statueLb.myRight = statueLb.myCenterY = 0;
    statueLb.mySize = CGSizeMake(50, 16);
    statueLb.layer.borderColor = COLOR_RED.CGColor;
    statueLb.layer.borderWidth = 1.0f;
    [contentLayout addSubview:statueLb];
    _stateLb = statueLb;
    _stateLb.transform = CGAffineTransformMakeRotation(-M_PI/6);
}


- (void)setClock:(XPlanDate *)clock{
    
    _titleLb.text = clock.time;
    [_titleLb sizeToFit];
    
    _countLb.text = [NSString stringWithFormat:@"%ld / %ld",clock.count,self.planCount];
    
  
    _stateLb.visibility = clock.count >= self.planCount?MyVisibility_Visible:MyVisibility_Gone;
    [_stateLb sizeToFit];
}

#pragma private -- Size

- (CGSize)systemLayoutSizeFittingSize:(CGSize)targetSize withHorizontalFittingPriority:(UILayoutPriority)horizontalFittingPriority verticalFittingPriority:(UILayoutPriority)verticalFittingPriority{
    
    CGSize cellSize = CGSizeZero;
    if (@available(iOS 11.0, *)) {
        cellSize = [self.contentLayout sizeThatFits:CGSizeMake(targetSize.width - self.safeAreaInsets.left - self.safeAreaInsets.right, targetSize.height)];
    } else {
        CGSize size = targetSize;
        size.width = size.width;
        cellSize = [self.contentLayout sizeThatFits:size];  //如果使用系统自带的分割线，请记得将返回的高度height+1
    }
    return cellSize;
}
@end
